package org.blueoxygen.kukuruyuk.actions.plasma;
import java.lang.reflect.InvocationTargetException;
import java.sql.Timestamp;
import org.apache.commons.beanutils.PropertyUtils;
import org.blueoxygen.cimande.gx.entity.GxDroplistValue;
import org.blueoxygen.kukuruyuk.entity.Plasma;
import org.blueoxygen.kukuruyuk.entity.Location;
import org.blueoxygen.cimande.LogInformation;

public class ChangeStatus extends PlasmaForm{
		
		private String locationId;
		private String dropValue;
		private String codeDefault;
		
		public String execute(){
			if(getPlasma().getId() != null && !"".equalsIgnoreCase(getPlasma().getId())){
				setPlasma((Plasma) manager.getById(Plasma.class, getPlasma().getId()));
				
				/*if (hasErrors()){
			}
				setDroplistValues(manager.getList("SELECT w FROM "+GxDroplistValue.class.getName()+" w WHERE w.name.id='8a8a8a931f5df886011f5e0a8cb80001'",null, null));
			return INPUT;
			}*/
			}
			getPlasma().getLogInformation().setActiveFlag(9);
			
			/*LogInformation log;
			if (getPlasma(). getId() == null ||
					"".equalsIgnoreCase(getPlasma().getId())){
					log = new LogInformation();
					log.setCreateBy(sessionCredentials.getCurrentUser().getId());
					log.setCreateDate(new Timestamp(System.currentTimeMillis()));
					getPlasma().setId(null);
			} else {
				Plasma temp = getPlasma();
			setPlasma((Plasma) manager.getById(Plasma.class, getPlasma().getId()));
			log = getPlasma().getLogInformation();
			try{
			PropertyUtils.copyProperties(getPlasma(), temp);
			}catch (IllegalAccessException e){
				e.printStackTrace();
			}catch (InvocationTargetException e){
				e.printStackTrace();
			}catch (NoSuchMethodException e){
				e.printStackTrace();
			}
			}
			 log.setLastUpdateBy(sessionCredentials.getCurrentUser().getId());
			 log.setLastUpdateDate(new Timestamp (System.currentTimeMillis()));
			 if (getPlasma().getLogInformation().getActiveFlag()== 1){
				log.setActiveFlag(9);
			 }
			 setLocation((Location) manager.getById(Location.class, getLocationId()));
			 
			 
			 getPlasma().setCode(getCodeDefault());
			 getPlasma().setLogInformation(log);
			 getPlasma().setRegion(getDropValue());
			 getPlasma().setLocation(getLocation());
			 */
			 manager.save(getPlasma());
			 return SUCCESS;
		}
		
		public String getDropValue() {
			return dropValue;
		}
		public void setDropValue(String dropValue) {
			this.dropValue = dropValue;
		}

		public String getLocationId() {
			return locationId;
		}

		public void setLocationId(String locationId) {
			this.locationId = locationId;
		}

		public String getCodeDefault() {
			return codeDefault;
		}

		public void setCodeDefault(String codeDefault) {
			this.codeDefault = codeDefault;
		}

}
		